﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeFamily.Properties;

namespace GeFamily
{
    class FamilyLevelCalculator
    {
        public static int[] FamilyLevelData;

        public static int[] RoleLevelData;

        public static int FamilyLevel;

        public static int RoleLevel;

        static FamilyLevelCalculator()
        {
            var a=Resources.FamilyLevel.Split(',');
            var b=Resources.RoleLevel.Split(',');

            FamilyLevelData = new int[a.Length];
            RoleLevelData = new int[b.Length];

            for (int i = 0; i < a.Length; i++)
            {
                FamilyLevelData[i] = int.Parse(a[i]);
            }
            for (int i = 0; i < b.Length; i++)
            {
                RoleLevelData[i] = int.Parse(b[i]);
            }
        }

        public static void Calc(int[] level)
        {
            var t = 0;
            for (var i = 0; i < level.Length; i++)
            {
                if (level[i] > 200) level[i] = 200;
                t += RoleLevelData[level[i]];
            }

            RoleLevel = t;

            for (var i = 0; i < FamilyLevelData.Length; i++)
            {
                if (t < FamilyLevelData[i])
                {
                    FamilyLevel = i;
                    break;
                }
            }
        }
    }
}
